package Server;

import Server.ChatServer;

import java.net.Socket;
import java.util.concurrent.ConcurrentHashMap;

public class ManageClientConnectionServerThread {

    private static ConcurrentHashMap<String, ChatServer> map = new ConcurrentHashMap<>();

    //管理线程的集合
    public static Socket getSocketByUserid(String userid)
    {
        //得到该用户的线程
        ChatServer thread=map.get(userid);
        if(thread==null)
        {
            return null;
        }
        else
        {
            return thread.getSocket();
        }
    }

    public static boolean existId(String userid)
    {
        if(map.containsKey(userid)) return true;
        return false;
    }
    public static void addThread(String userid,ChatServer thread)
    {
        map.put(userid,thread);
    }

    public static void deleteSocket(String userid)
    {
        map.remove(userid);
    }

    public static ConcurrentHashMap<String, ChatServer> getMap() {
        return map;
    }
}
